In [6]:
import json
from pprint import pprint
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [7]:
landing_page = []
goal_one = []
with open('task_data/Goal1CompletionLocation_Goal1Completions.json') as data_file:
data = json.load(data_file)
list_of_dict = data['reports'][0]['data']['rows']
for dictionary in list_of_dict:
landing_page.append(dictionary['dimensions'][0])
goal_one.append(int(dictionary['metrics'][0]['values'][0]))
goals_df = pd.DataFrame(data = {'page': landing_page, 'goal_one': goal_one})
goals_df.head()
Out[7]:
In [8]:
landing_page = []
sessions = []
with open('task_data/Sessions_Page.json') as data_file:
data = json.load(data_file)
list_of_dict = data['reports'][0]['data']['rows']
for dictionary in list_of_dict:
landing_page.append(dictionary['dimensions'][0])
sessions.append(int(dictionary['metrics'][0]['values'][0]))
sessions_df = pd.DataFrame(data = {'page': landing_page, 'sessions': sessions})
sessions_df.head()
Out[8]:
In [9]:
merged = pd.merge(sessions_df, goals_df, on='page')
merged['conversion_rate'] = merged['goal_one'] / merged['sessions'] * 100
merged
Out[9]:
In [13]:
max_info = merged.loc[merged['conversion_rate'].idxmax()]
print ('The best converting page on your site is "{}" with conversion rate {} %.'.format(max_info['page'],max_info['conversion_rate']))
y = merged.conversion_rate
N = len(y)
x = range(N)
plt.xticks(x, merged.page, rotation='vertical')
plt.ylabel('Conversion Rate')
width = 1/1.5
plt.bar(x, y, width, color="green")
plt.show()
In [ ]: